<template>
<view>
<form @reset="formReset" @submit="release" reportSubmit="true">
    <view class="modle">
        <input class="modle_right btm_input" name="phone" placeholder placeholderStyle="color: #9295A8;" type="number" :value="userphone">
    联系电话
    <text class="must_red">*</text>
        <button @getphonenumber="getPhoneNumber" class="modle_btn" open-type="getPhoneNumber">电话授权</button>
    </view>
    <button class="bufa_btn" form-type="submit">提交</button>
    <view class="jinggao">提交后销售顾问会与您联系</view>
</form>
<!--<import src="/pages/alert/index.wxml"></import>-->
<block data-type="template" data-is="alert" data-attr="isShow:isShow">
    <view class="wx_dialog_container" :hidden="!isShow">
        <view class="wx-alert-mask"></view>
        <view class="wx-alert-dialog">
            <view class="wx-alert-dialog-title">尊敬的用户</view>
            <view class="wx-alert-dialog-content">尚未获取到您的用户信息，较多功能无法体验，请允许获取用户信息</view>
            <view class="wx-alert-dialog-footer">
                <button @tap="hideDialog" class="wx-alert-dialog-btn">拒绝</button>
                <button @getuserinfo="updateUserInfo" class="wx-alert-dialog-btn" open-type="getUserInfo">允许</button>
            </view>
        </view>
    </view>
</block>
</view>
</template>

<script>
var app = getApp(),
    upurl = app.globalData.util.url("entry/wxapp/Api", {
  m: "monai_sharing",
  uid: wx.getStorageSync("uid"),
  r: "Upimg"
});

export default {
  data() {
    return {
      upcarindex: 0,
      userphone: "",
      isShow: !1,
      status: "",
      buttscan: ""
    };
  },

  components: {},
  props: {},
  onShow: function () {},
  onLoad: function (e) {
    var t = this;
    app.globalData.util.getUserInfo(function (e) {
      e.memberInfo || t.setData({
        isShow: !0
      });
    }), t.firstin(t);
  },
  onReady: function () {},
  onHide: function () {},
  onUnload: function () {},
  onPullDownRefresh: function () {},
  onReachBottom: function () {},
  onShareAppMessage: function () {},
  methods: {
    hideDialog: function () {
      this.setData({
        isShow: !this.isShow
      });
    },
    updateUserInfo: function (e) {
      var t = this;
      app.globalData.util.getUserInfo(function (e) {
        wx.setStorageSync("uid", e.memberInfo.uid), t.hideDialog();
      }, e.detail);
    },
    firstin: function (a) {
      wx.getSystemInfoSync();
      app.globalData.util.request({
        url: "entry/wxapp/Api",
        data: {
          m: "monai_market",
          uid: app.globalData.getuid(),
          r: "sale.index.saleindex"
        },
        cachetime: "0",
        success: function (e) {
          var t = {
            userphone: ""
          };
          e.data.data.user && (t.userphone = e.data.data.user.phone), a.setData(t);
        }
      });
    },
    getPhoneNumber: function (e) {
      console.log(e);
      var t = this;
      app.globalData.util.request({
        url: "entry/wxapp/Api",
        data: {
          r: "sale.index.userphone",
          m: "monai_market",
          iv: e.detail.iv,
          encryptedData: e.detail.encryptedData
        },
        cachetime: "0",
        success: function (e) {
          t.setData({
            userphone: e.data.data
          });
        }
      });
    },
    release: function (e) {
      var t = this,
          a = wx.getStorageSync("uid");

      if (a) {
        if (!t.buttscan) {
          t.setData({
            buttscan: !0
          });
          var n = e.detail.value.phone;
          if ("" == n || "undefined" == n) return app.globalData.util.message({
            title: "请点击电话授权",
            type: "error"
          }), void t.setData({
            buttscan: !1
          });
          var i = {
            r: "sale.index.inloan",
            m: "monai_market",
            fomid: e.detail.formId,
            uid: a,
            phone: n
          };
          app.globalData.util.request({
            url: "entry/wxapp/Api",
            data: i,
            cachetime: "0",
            success: function (e) {
              console.log(e), e && e.data && wx.showModal({
                title: "成功提示",
                content: "提交成功",
                showCancel: !1,
                success: function (e) {}
              });
            },
            fail: function (e) {
              console.log(e), wx.showModal({
                title: "错误提示",
                content: e.data.message,
                showCancel: !1,
                success: function (e) {}
              });
            }
          });
        }
      } else t.setData({
        isShow: !0
      });
    },

    formReset() {
      console.log("占位：函数 formReset 未声明");
    }

  }
};
</script>
<style>
@import "./index.css";
</style>